package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apiguardian.api.API;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.naming.spi.ResolveResult;
import java.util.List;

/**
 * 护理项目controller类
 */
@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {
    @Resource
    private NursingProjectService nursingProjectService;

    /**
     * 护理项目分页查询
     *
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation(value = "护理项目分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称") @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态:0-禁用，1-启用") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示条数") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize

    ) {
        log.info("护理项目分页查询：name={},pageNum={},pageSize={},status={}", name, status, pageNum, pageSize);
        //接收参数
        //调用服务
        PageResponse<NursingProjectVo> vo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        //响应数据
        return ResponseResult.success(vo);
    }

    /**
     * 新增护理项目信息
     *
     * @param dto
     * @return
     */
    @PostMapping()
    @ApiOperation(value = "新增护理项目", notes = "传入护理项目对象")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto dto) {
        log.info("新增护理项目：dto={}", dto);
        //接收参数
        //调用服务
        nursingProjectService.addNursingProject(dto);
        //响应数据
        return success();
    }

    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目", notes = "传入护理项目对象")
    public ResponseResult<NursingProjectVo> getById(
            @ApiParam(value = "护理项目id", required = true)
            @PathVariable Long id) {
        log.info("根据id查询护理信息 id={}", id);
        //接收参数
        //调用服务
        NursingProjectVo vo = nursingProjectService.getById(id);
        //响应数据
        return success(vo);
    }

    /**
     * 更新护理项目
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "更新护理项目",tags = "传入护理项目对象")
    public ResponseResult update(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto dto){
        log.info("更新护理项目 dto={}",dto);
        //调用服务层
        nursingProjectService.update(dto);

        return success();
    }

    /**
     * 启用禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理项目")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "护理项目ID", required = true) @PathVariable Long id,
            @ApiParam(value = "护理项目状态", required = true) @PathVariable Integer status) {
        nursingProjectService.enableOrDisable(id, status);
        return success();
    }

    /**
     * 根据ID删除项目信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据I删除护理项目",tags = "传入护理ID")
    public ResponseResult deleteById(
            @ApiParam(value = "传入护理项目ID",required = true)
            @PathVariable Long id){
        log.info("根据id删除项目信息 id={}",id);
        nursingProjectService.deleteById(id);
        return success();
        }

    /**
     * 查询所有护理项目
     * @return
     */
    @GetMapping("/all")
        @ApiOperation(value = "查询所有护理项目")
        public  ResponseResult<NursingProjectVo> findAll(){
        log.info("查询所有护理项目");
        //TODO
        return success();
        }
}